Fixed syntax error and further optimization of code