fixes #10. adding tests and implementation