Fixed javascript math bug