Refactor and optimize move generation

Change: introduce variables for common statements.
Change: improve variable names.