Added try..catch block to catch IllegalThreadStateException