Added debug and minor changes