More speech recognition logic, misc optimization