pull out format header function
moved var ``twice" out to the inner loop
set the search bound to -1 (nearly infinite)