Moved defs outside of run() and cleaned up comments