Modified create_function and added shortpath function