Finished the port (minus pretty printing).