implementing transactional. Not fully tested yet