First round of unit tests and improved sequence number handling