Fix header bug (spans did not match all possible cases). Also make sure the lib cases are optimized by breaking out when possible.