fixed handling for small keys.
small adjustments for python 2.7