turn it all into middleware