refactored mysql transaction functions