Fixed a lot of critical bugs