modularized and cleaned up the scripts, may do more modularization in the future