implement Ryan's changes and make the tests pass

Signed-off-by: Luca Degasperi <luca@lucadegasperi.com>