fix some warning and add some error check functions