optimized the expressions and fixed some bugs