Given an undocumented and inefficient legacy Python function in an online code-pad, perform a code review and refactor the code.
Write a cleaner, faster version of the function with the same behavior. Keep the public function signature unchanged, and preserve the expected input and output shapes used by the tests.
def refactor_legacy_function(data):
data: the function input used by the legacy implementationdef refactor_legacy_function(data):