OK, still ugly but now can be used as a module too