refactor to tidy functions