fix bugs causing app crashes