implemented everything. passes all tests.