In dire need of some refactoring (also put as "looks ugly"), but it works. TODO refactor write a proper README file