changed, unneccessary charAt with indexOf, code Style correction, added invalid URL case for query after fragment