refactored move gen code