code changed for better understanding