Added better model handling and transaction management