Moved function to start of file