fix url and tidy up code