adding tests and changing the logic accordingly