Bugfixes and some code cleaning

Also removed unneeded files.
Now works pretty well.