Updated to handle null headers, thanks @bamos
Moved import into correct place