Moved code around so xhr happens last