Extract code from main.rb and create new class

To ensure loose coupling. Some stuff is still not properly working, but I gotta stop for now..