Fixed bug where magic_index could return nil in many cases