Fix order of function definitions
More updates to support building statically (and it's still optional)