adding tests and fixing small bug