Code factoring and some utils.