Modularise phi lib