added Debug and fixed a few bugs