Code refactorization, added client and REST tests