added main function and fixed precedence order in reduceAnd