Fixed few bugs that cause crashes.