Add tests, logger and fix bugs