little refactor and fixing order by