fix serval bugs found in code review