Added debug output & minor fixes