enclosed everything in a try catch block so that curses session is closed despite errors