Moved most of the code into a class (ILP).