adding tests and fixing small bugs