moved get order ogic to lib, in order to make future updates simpler