Cleanup

remove unused code, cherry-picked from reduce-mem footprint which is work-in-progress
This is ready to merge