Calculate sin and max only once