error handling and better console logs