implement the emit phase
add tests for emit phase and clean up tests