Clean up code and avoid hex conversions for each check