correct memory tracking, remove unused code