Refactored to use cfscript functions

Please review the code and decide if it's good.