Refactor with JavaScript bezier curve calculation and bug fixes.