finished up, added proper sorting