Fixed some bugs, added logging capabilities