updated code logic