added error handling and extra feature: prompt