Added basis tests and implemented better error handling.