Made more testable and added tests