Error handling and better documentation