added codes for replacing population