made changes to the logic to catch all the possible results