Fixing getcontents to use only local variables