Refactor afp.js into different files