Fix a silly sizeof error. By rewriting the whole function.