add error handling and better comment