Fix bug where closing bracket is inside if statement