cleanup and refactor to fix