Changed the bracket algorithm