fixed bug, added debug output