Added character class and refactored code