back port some changes from no_label branch