Some code refactored.