added logging and loop