refactored database transactions