Moved pages calculation into _state functions