better reference handling