take into account multiple brackets in function