Reorganized and added unit tests