Revert "Revert "various imrovements""

This reverts commit 5f2a8e207a06cee89b653713db4c955f633fbd37.