fix magic function