  We develop refinements of the Levenshtein bound in $q$-ary Hamming spaces by
taking into account the discrete nature of the distances versus the continuous
behavior of certain parameters used by Levenshtein. The first relevant cases
are investigated in detail and new bounds are presented. In particular, we
derive generalizations and $q$-ary analogs of a MacEliece bound. We provide
evidence that our approach is as good as the complete linear programming and
discuss how faster are our calculations. Finally, we present a table with
parameters of codes which, if exist, would attain our bounds.
