Stay safe against bad input
Added support for context (needs refactor)