improved performance and refactored.