Refactor and comment varlen functions