Improve many small things

Prevent some code duplicating, and ensure the same behaviour.