added debugging and loops