fixed magic function