fix #306 and #313

Hmm not sure this is what you asked, is it supposed to pollute the global namespace like that?