More sophisticated square bracket reference handling