Refactored url parsing