update readme.md + refactor nearly duplicate code