removed a small bug and added some debugging