Code clean-up, more logging and avoiding exceptions