wrote commit function - JM