moved some statements to try block, added useful logs