Implement deframer and add unit tests