refactor n-queens