#240 added security checks, and improved test coverage