Refactored and fixed bug with valid product method to improve performance