Second optimisation pass