Fixes a lot of code mistakes