More logic changes and add missing imports