Simplifying code on error case