Refactor and ensure valid values