Added unit tests and unpolluted scope.