Improved checkbox logic