added try-catch-block and added variables