Optimized and reformatted code.  Added more information to log messages.