Refactored avatar code.