better url decode function, change redirect code