implemented a basic loop logic.