Code cleanup; preparation for #2675 

#2675