Fix error 1009

This change includes a handful of unrelated changes meant to eliminate cases where we sometimes try to access a property or method of a null reference.
See also LLK/scratch-flash-online#45