move magic to function wrapper