move avatar logic into directive