Fixed error processing, added more tests