Revised and improved serialize method in base.