Add sanity checks, comments.  Initial functionality.