fixed some bugs on generating the right url