Refactor exercises to algorithms to support generic savinf of data