Start to translate http://bluishcoder.co.nz/2010/06/13/functions-in-ats.html