added fallback and restructured script