cleaned up code, fixed url function