Finished Refactoring unit tests and error checking