Rewritten script and added options for compounds and replacement tables