Helper methods for TokenStack, new functions min and max, code clean-up