improved errors handling