simplified main control flow a bit