Fix brackets and boolean logic