fixes for bugs and crashes