added some type checking and clearer message on type errors
added rdoc
restructured samples