added last part of IA algorithm