added support for building to more then 3 ends