MRDKA to FIRST_BY and LAST_BY refactoring