Added most logic. Need to actually run commit command when applicable