Bug fix + added debug flag