finished refactored