Add support for checkbox, clean up the code