Fixes for invalid variable references and debugging improvements

Patches that improve debugging (by not calling non-existent functions and printing a helpful message) and fix some invalid variable/function references.