Restructured and added unit tests