Recovery of thermal energy