Added some log and exception catching