refactored some of the bits