some bug fixes and crashes with server

Signed-off-by: cout970 <thecout970@gmail.com>