added some tests and changed some logic