move http status code logic up