completed solution for multiple brackets