fixed broken tests and refactored