a little bit optimized version, remove unnecessary code