partial rewritten. fix NOT_FOUND bug