Bug fixing; added try catch statement for better debugging