rewritten code to use .done method