bug fixes. Added debug -d option