some cleanup and refactor