refactor to include logging