Refactor code for memwin and pgmwin modify