few unused imports removed, some refactoring.