implemented State pattern