refactored and tidied up main program file, removed redundant comments