Add logging and paranoic exception handling

Add logging and paranoic exception handling