Updated with some simple error handling