Major commit.  Return error codes, added json as a result option, templating.