STEP: code optimization + some fixes
Revert "STEP: code optimization + some fixes"

This reverts commit 616f5f9de7c9b580ba21a1298d802a1d446e8a95.