fix small bugs and invalid access error