Added some more error checking to avatar upload

Still not perfect and still may have bugs in it.