Fix issue with selecting then deselecting a cell without dragging

Refactor a bunch of for loops in to "functional" constructs because javascript