Changed implementation and created some unit tests