made use of Optional chains instead of reduce function