pit and some minor refactoring