added comments and small code aesthetics modifications