More HLS optimizations - no changes in functionality.
Fixed problem with closure on FreeBSD machines.