More fixes and refactorings. Add example code to README