copy from master-branch
introduces function calls