Adding some tests and cleaning some code