added optimize largest algorithm