bug fixes with gradient calculation and ghost cells