First working version
Refactored version with simple debugging possibilites