fixed loop, cleaned up