fixed array sorting function