moved service logic from middleware into service