Code now working for non-half-filling