Fixed code logic issue