updating better codes to run in loops