moving avatar variable and functions to separate file
splitting up lots of client-side code

This really is too much for one commit, but unfortunately it's a lot of tangled dependencies.