Fixed bugs. First working version