refactor and cleanup - first part