refactored, added a few bits and pieces