Refactor stateless stuff into *_stateless.[ch] and implement some of the logic.