Portable logical operators and change varible max into maximum to avoid conflicts with standard c++ max function