Replace array with map to prevent illegal access