Fixed a few crashes and a few bugs