Bugfixes
Change from script to function
Rewritten to use new metadata