Reworked TTS filtering logic for readability and safety, added comments