Fixing bug where helper function was not being called correctly