cleaned character manipulation code based on enumeration