Add test and fix readme code example to work correctly