removed double buffering and unnecessary debug print statement