Why is the check box function not working properly?