revised all_data function and cleaned up code