fix compile issues and array out of bound