This multi line type writing code is taking too much CPU usage and memory. Please fix this. I believe sleep function is causing that. Please suggest some alternate solution.