fixed all tests and bugs: Ryan please see the TODO comments