cleaned up and added tests