refactoring (continued from previous commit)