added extract and swap function and gave proper documentation to all funcs