rewrote flags init. fixed -d sort bug