fix bugs and add randomly order function