Bugfix.
Code restyle and tests added.