Some fixes

I had some free time today, so I tried to fix the problems as far as I could. Check it out.