I don't think you handle len == 0 very well here.