more refactor and cleanup