Switched out my manual math for using Javascript instead