refactored heap a bit