aesthetics changes

code moved around to make more logical sense and added comments