adding tests and fixing bugs