Fixed bug, added some debugging output.