Add unit tests and implementation