Bugs fixed. First working version of the code ready