! Actually fix #2375 this time, and do some general code cleanup as well