Fixed header parsing, and added tests