fix transactional behaviour, refactor