Converting the code in a library

The `callback` function is the most important change here. Look in the README to see the new example.