Revert "Revert "code cleanup""

This reverts commit 77b5af85ae550bfaca5d45c629086d7fc6fcdf02.