Added working unit tests and split up class to be more testable