Re-implementation, more tests