Moved function call to prevent null pointer