adding tests and fixing some small bugs