Refactored loop(), update comments