Removed boilerplate code from database middleware