Refactor with advice from fgs