added 303 redirect and some handling of errors