Add better exception handling