middleware improvement