added state object, much cleaner mutable code