refactor status code logic