Update with refactoring ideas - still not finished