Add some simple error handling and edge cases.