added several tests and code is almost finished.