Added UpdateThread and fixed a logic bug