more refactoring: added state pattern