Add more unit tests, add some exception handling