example works after refactoring, a lot of minor fixes