first functional code (untested)
some errors fixed, now it compiles
preparing format for a good integration