Attempts to fix NPE and OutOfMemoryError in avatar related code.