Moved retry logic to separate files

+ Refactored parts of the low level REST calls.