Added more debugging info and fixed some bugs