Better error handling and number formatting