Rewrite to lib
Run loop