more code refactoring - COMPLETE