Fixed redirect by doing form processing before header is sent.
Changed url function to avoid accidentally deleting something.