fixes, tests and coding style