Used your version, but added a template for beginTransaction method