new JavaScript for better compatibility

Moved functions for calculating and dispalying stuff at the end, works in Safari as well