Fixing some bugs and adding logs