move phantom code to lib