fixed bug with null in context.head - use !ctx instaed of ctx ===
undefined to avoid issues when ctx is null/false/0 and so on.  also
DRY'd the flag switch