Got a working implementation.