Changed database wrapper to work on a transactional basis