Various bugfixes. (#463, #462, #461, #460, #459, #458)