Fix for infinite loop in commit function