Fix variable scopes. Do compile check