added a few debug outputs, made graph matrix stricter