token input and some complicated crap