Add error logging and test