changed mapply to mdply for overall readability