Fixed a but
Enhanced logging and fixed a bug.