Removing syntax error and redundant calculation