Adds support for passing flags to New()

It also has a minor fix to report magic cookie allocation errors.