Refactor by use for to loop round