Improved config validation

Re-wrote config validation in a more robust and re-usable way, and
added documentation for all currently existing public functions.