Scriptapi split + move to subfolders (rebased)

Rebased version of #677.