Fixed some bugs, temporary debug outputs