refactored and improved.