Fix bug in sleeping algorithm
React appropriately to internal server error