All tests working
TODO: code really needs a refactoring, some improvements, can be done. 
TODO 2: remove useless functions