The best thing I think you can do here is create a hashmap of your incoming parameters.  It will let you do a lot more and you can eliminate a few of your loops with it.  The hash map seems like it would be best as key:avatarid and value:accountid for later lookups