Cleaned up state, functional instead of IORefs