fixed up some bugs, switched from arr to object to keep track of positions