refactored some length hash lookups