Fix some invalid reference bugs