control flow and grammar improvement