Chat: factoring code