Add and fix unit tests