adding more cases and reorganized for more DRY code