fix forget-to-vfree problem and optimize some code