moved function call out of delegate