Handle a few edge cases, better error handling.