initial version, very basic and buggy.
Will be refactored, optimized and tested somewhen.