Fix halt issues, but still need to work on global variables.