Replace brackets where necessary