Removed spurious newline.
Partial beam bug fix
Clean up unnecessary code
Moved function declaration out of inner loop.