Script almost enterely rewritten

Rewrote from scratch (with pieces of the previous version obviously).
Hopefully, the code is a bit cleaner and will be easier to maintain and
extend.

I got rid of some bugs and tried to improve UX. Details to be found in
Readme.