Added options to middleware function, to allow the TAL application ID to be set