Fixed a multitude of bugs