For best speed do this as a module so that you can utilize function/variable localization much better.