Refactored path handling, added query string support