three step algorithm