almost finish, has a infinite loop somewhere