Fixed bugs and added new tests.
Merge branch 'origin/master'