alan refactored