improved library for creating order, some refactoring