Refactor functional bits