Tidy and refactor