Refactored some methods, better comments and moved initial CM loaded check to top of script (no more global flag)