version 2 - refactoring (not yet complete)