Add validation, fix profiling for a few functions.

Related to #7