new version with support for defstruct options and some error checking