fix bracket counting