fixing thread bug (Nullpointerexception)