added options for controlling execution for #6, refactored a few things in the process and cleaned others.