Improve JS calculations