Extract logic from script file to class