fixed header isssues
Same features as previous commit with minor bug fixes.