Implementing iterator according to specification