refactoring complete. back to where we were, but with cleaner code...