Put code into a class

and some other adjustments...