refactor with commit() helper

meh pretty lame but at least it gets it out of nested braces