Fixed a few crashes due to logical errors missed in refactoring