Improve logical check and syntax