Fixed error handling. It should all work now