reversed box selection logic and fixed a few small bugs