cleaned up code, some tests still needed