debugging version
fixed version with correct diagnostic output