bug fix and debugging