moved function definitions to the bottom