fix loops, cleanup