this code more elegand and correct