optimize shell scripting
fix boundery issue