Refactor memory queue bussiness logic