Proper transaction management by commiting, rolling back and closing connections under various cases.