More improvements

Second round of misc. improvements. Feel free to apply as a whole or cherry-pick what you like.