moved estimate code to loop