A bit of refactoring + fixes #10