Reorganize request code to make it a bit more robust