added more tests and more functionality and extracted to a factory