Moved some functions into separate JS file