refactored and added example to readme