Made generic IA function. There are problems with the threads