rewrote program so array handling uses pushes and shifts