copied code from adapy. separating several sub-modules to make it easier for me to get an overview