! refactor a lot

Hi @philippotto,

To add more features easily, I think we should refactor the code first. This is my attempt. Hope you like it.