Cleaner way to handle errors