fixed bugs causing crashes