calculating the remainder for master and stack area correctly