A few minor changes and improvements (reverted from commit 04f538e42c426fa0b5cff42ece7aa0cd4982360a)