Fixed crash-causing bugs.