added various tests and logic