extract function added and complete