Fixed function scope and buffer len read error