Reorganize code and clean up

Reordered the code moving all the GetMoves for pieces below the marker,
and reusable functions are shown above them.