Fixed a shitload of bugs