first freezed algorithm