Fixed the t_flat and r_flat routine