Cleanup: moved rest of the code to a new class.