code refactor based on Arthur & Fred's comments