Fix bugs in code, added log