cleaned code used thread