Getting right function from middleware