added loop with try error detection