made some important changes like error handling