Fix bugs mentioned by Bas080