Fix multiple problems with 499b7c55e153b8567ecaeabd03e3ee4a9c4fd8a8