Implementation of steps 1 to 5