Factorized BaseModel in own file, bugfixes and test revision.