Added populate and validate functions, plus some general clean-up.
Added initial unit tests.