implementing the State design pattern