Cleaned up javascript to make it more readable.