moved function to main script