Also reset state on function entry otherwise split_url() cannot really be called multiple times since there would be garbage values in the url array from previous calls.
Also stop leaking local variables