refactored alot of code and tests ready for new features