Moving state into database