Just something that caught my eye is that the options are taking up a lot of code lines. Not really a real issue but I think a lot of it could be turned into reusable functions. For instance a generatePositionOptions() function would make a lot of sense.