Partially refactored