address comments and add rails middleware documentation