Add error handling and refactor