Instead of UnitCastAimedSpell(unit,spell,target), use startThread(UnitCastAimedSpell,unit,spell,target). The error will remain, but it won't affect the script's further execution.
StartThread doesn't seem to work; it appears that you can't start multiple threads during combat.