finished logic with some tests