stage 4 (not finished), refactoring