Cleans up and organizes the JS functions a bit.