Moved program termination to new method and added comments and structuring