logic works except brackets and the first negative number