Fix some warnings and potential bugs.