Incorporated error handling along with some tests.