Fixed some possible errors and added debug code