Added validations against header and made other minor tweaks.