rewrite the product code,made it more flexible