Added max_files parameter. Also made numerous aesthetic changes.