Added command logging and various bug fixes