added double brackets to ifs inside function, issue #34