refactor URL writing