Moved function code into separate JS file.