adding -lm, removing newline warnings, make sure JS loads in correct order