Fixes adapted from @Nothing4You.