make middleware more transparent in index
minor example edits
move callback function to example.