Added type information and refactored.