Cleanup and moved helper function to separate JS file