Fixing a javascript bug where position is required twice