Moved atinit functions to bottom of file to fix scope issues