implemented 3-pass build