Clean up and add input validation to mask decoder