bug fix and some more debug prints