prevent deadlock
fixed possible null pointer exception