Refactored checkbox function to check for multiple selections