Misc refactorings. Started working on the StreamClient.