Add some checks before calling functions to allow collection support.
Merge pull request #5 from otang/b/robust

Add some checks before calling functions to support collections in addition to models.