intial algorithm for brackets