improve code logic