Shitty coded but workable version

Need ofr a lot of refactoring and optimization. Still need for good tree
representation.