better loop nearly working