Converted to a library and added example