fix leaking global variables

, , & d are all leaking into the global scope