almost synced with database

The image write, addUser and addFriends haven't been moved over, but
most of the rest of it relies on the database now.