Make the pain go away.

Fix #581, #544, #541, #535 and a few others.