added comments and moved around variables