refactor to remove local variables