refactor and cleanup complete