added header extraction and refactor errors