Made some changes suggested by @aaugustin