Refactor shared code and make requested changes