Completed code with all steps, simplified new code