refactoring continued (yet still intermediate, disfunctional version)