added more try-catch and IOexception