fixed a few major crash causing bugs