Fixed some bugs that were making commands not work in a lot of cases.
Progress towards #3