Working version with some tests