Added a lot of implementation and tests