Full implementation and tests - fixes #13