Simplified code. But, this takes more time to run!!