A large group of small fixes, tweaks and cleanups

This PR is full of small fixes, tweaks and cleanups.