fixed bug and added debugging macro