fixed loop, many tweaks