almost finished refactor