General cleanup (see commit comments for details)