remove tabs; fix loop detection