Improved error handling.
Code clean-up and refactoring + better argument checking + use std::string where appropriate.