fixed bugs and crashes