Fixed bugs. Create Unit tests