Added tests.
Added error logging.