fixed logic + formatting