added onelined main algorithm.