Added tests and did some re-org.