factored out some invariant cos calls