fixed logic issue
added test