adding tests and modifying to be more readable