Upgrade to version 2

Massive rewrite from version 1 to make it more stable and versatile