fix global underscores and macros; clean up main loop logic/readability