finished the complete function