added marginally better error handling