Cleaned up URL generation code for toclabel