moved function call to fix undefined